Hi all - i'm trying to create a script that will print a list of users and their email addresses. This is simple enough but I have a number of diabled users and i want to discount them from being printed.
Searching through the DXL reference file shows "disabled" as the boolean property I need to use- presumably with a "true" value meaning the user is disabled.
So a simple if loop looking for false should only bring in non disabled accounts:
User usr
for usr in userList do
{
bool bldis
bldis= usr.disabled
if (bldis=false){
string strEmail, strName
strEmail= usr.email
strName=usr.name
print strName "," strEmail "," bldis "\n"
}
}
The code generates with no errors, but prints nothing - if you change the value to "true" it prints every user in the database - presumably implying that doors thinks that all of the users are disabled? printing the bldis property shows that there is a "true" next to each user for this. I'm assuming i'm actually using the wrong property and the disabled property it something else - to clarify- I have been disabling users using the tick box in the user management section.
I'm not a very experienced DXL coder so I expect I'm doing something very obvious wrong. Any help appreciated.
(Initially I tried a higher level if loop, without bothering to create the boolean memory etc but this gave the same results.
DanBow - Wed Jun 20 04:55:28 EDT 2012 |
|
Re: User disabled property adevicq - Wed Jun 20 05:00:10 EDT 2012
Hi,
In your "if" you have to use "==" to compare the values:
if (bldis==false){
...
}
regards,
Alain
|
|
Re: User disabled property DanBow - Wed Jun 20 05:04:32 EDT 2012 adevicq - Wed Jun 20 05:00:10 EDT 2012
Hi,
In your "if" you have to use "==" to compare the values:
if (bldis==false){
...
}
regards,
Alain
Hi thanks for the reply - it actually runs the code both ways but using "==" doesn't change the result in that it still displays either no users with "false", or every user in the database with "true", despite having multiple disabled users in the database - leading me to believe I'm using the wrong property
|
|
Re: User disabled property adevicq - Wed Jun 20 05:14:31 EDT 2012 DanBow - Wed Jun 20 05:04:32 EDT 2012
Hi thanks for the reply - it actually runs the code both ways but using "==" doesn't change the result in that it still displays either no users with "false", or every user in the database with "true", despite having multiple disabled users in the database - leading me to believe I'm using the wrong property
Well! If all the users are displayed when you test with "true" it is probably that:
-
all of them are disabled
-
the atribute does not mean what you think...
If you remove the test (if (true) ...), can you see any "true" at the end of your exported lines? If not then no one is disabled...
Alain
|
|
Re: User disabled property DanBow - Wed Jun 20 05:43:41 EDT 2012 adevicq - Wed Jun 20 05:14:31 EDT 2012
Well! If all the users are displayed when you test with "true" it is probably that:
-
all of them are disabled
-
the atribute does not mean what you think...
If you remove the test (if (true) ...), can you see any "true" at the end of your exported lines? If not then no one is disabled...
Alain
I obviously know for sure that all of the users are not disabled - and instead just a few. So yes as I said - I think I must be using the wrong property in the code and thus hope to find out the correct one.
(Yes, if I take the if loop out it just displays every user in the database with true next to them - implying that every user in the database is disabled, which is not the case).
Perhaps there is another way of disabling a user that I am unaware of that feeds into this property?
|
|
Re: User disabled property DanBow - Wed Jun 20 05:44:14 EDT 2012 DanBow - Wed Jun 20 05:43:41 EDT 2012
I obviously know for sure that all of the users are not disabled - and instead just a few. So yes as I said - I think I must be using the wrong property in the code and thus hope to find out the correct one.
(Yes, if I take the if loop out it just displays every user in the database with true next to them - implying that every user in the database is disabled, which is not the case).
Perhaps there is another way of disabling a user that I am unaware of that feeds into this property?
(Thank you for the help though)
|
|
Re: User disabled property DanBow - Wed Jun 20 05:49:38 EDT 2012 DanBow - Wed Jun 20 05:44:14 EDT 2012
(Thank you for the help though)
Upon running the code again it's now displaying correctly which is very strange - something to do with the if loop as you mentioned. The value seems to change if I run the loop or not.
If I take the loop out it will show false values where i would expect them, however if i put the loop back in, the value changes to true for each of them. I guess what may be happening is that the for loop is out of sync and only showing the true value for one user - but showing it for each user.
|
|
Re: User disabled property SystemAdmin - Wed Jun 20 05:51:23 EDT 2012
Even though you think the script works with using either "=" or "==", it's not.
Now others can possibly explain this better than I can but here goes.
The statement within parenthesis (bldis = true) is not actually performing a conditional test, it is actually forcing the boolean variable "bldis" to be equal to "true".
So the line "if (bldis = true)" becomes the same as writing "if (true)" so the conditional "if" statement is always resolving to be true and consequently you get a listing of every user.
I find that your script works fine if you use "==".
BTW - as a tip, if you use the code mark up tag above and below your code, it will look like the following - (all mark up tags are listed in the Plain Text Help box that appears next to the DW Forums editor.
I've added indentation and a few other pedant type adjustments
User usr
bool bldis = false
for usr in userList do {
bldis = usr.disabled
if (bldis == false){
string strEmail, strName
strEmail= usr.email
strName=usr.name
print strName "," strEmail "," bldis "\n"
}
}
Paul Miller
Melbourne, Australia
|
|
Re: User disabled property DanBow - Wed Jun 20 05:58:03 EDT 2012 SystemAdmin - Wed Jun 20 05:51:23 EDT 2012
Even though you think the script works with using either "=" or "==", it's not.
Now others can possibly explain this better than I can but here goes.
The statement within parenthesis (bldis = true) is not actually performing a conditional test, it is actually forcing the boolean variable "bldis" to be equal to "true".
So the line "if (bldis = true)" becomes the same as writing "if (true)" so the conditional "if" statement is always resolving to be true and consequently you get a listing of every user.
I find that your script works fine if you use "==".
BTW - as a tip, if you use the code mark up tag above and below your code, it will look like the following - (all mark up tags are listed in the Plain Text Help box that appears next to the DW Forums editor.
I've added indentation and a few other pedant type adjustments
User usr
bool bldis = false
for usr in userList do {
bldis = usr.disabled
if (bldis == false){
string strEmail, strName
strEmail= usr.email
strName=usr.name
print strName "," strEmail "," bldis "\n"
}
}
Paul Miller
Melbourne, Australia
Apologies and thanks to both of you.
"The statement within parenthesis (bldis = true) is not actually performing a conditional test, it is actually forcing the boolean variable "bldis" to be equal to "true"."
This makes sense to me....now.
I did try switching to "==" earlier and it seemed to not make a difference but clearly I didn't run it properly as everything works fine now.
|
|
Re: User disabled property SystemAdmin - Wed Jun 20 06:05:30 EDT 2012 DanBow - Wed Jun 20 05:58:03 EDT 2012
Apologies and thanks to both of you.
"The statement within parenthesis (bldis = true) is not actually performing a conditional test, it is actually forcing the boolean variable "bldis" to be equal to "true"."
This makes sense to me....now.
I did try switching to "==" earlier and it seemed to not make a difference but clearly I didn't run it properly as everything works fine now.
When programming in C or DXL or the like, you should always write the constant value to the right side of the equal signs in a comparison.
So, if you forget an equal sign, like in
if (true = bldis)
you will get a compiler error, which tells you soon enough that something went wrong....
|
|
Re: User disabled property SystemAdmin - Wed Jun 20 06:10:18 EDT 2012 SystemAdmin - Wed Jun 20 06:05:30 EDT 2012
When programming in C or DXL or the like, you should always write the constant value to the right side of the equal signs in a comparison.
So, if you forget an equal sign, like in
if (true = bldis)
you will get a compiler error, which tells you soon enough that something went wrong....
aaargh. to the left side of course.
Left, Mr. Stimpson? Right! Left!
|
|
Re: User disabled property llandale - Wed Jun 20 14:30:44 EDT 2012 SystemAdmin - Wed Jun 20 06:05:30 EDT 2012
When programming in C or DXL or the like, you should always write the constant value to the right side of the equal signs in a comparison.
So, if you forget an equal sign, like in
if (true = bldis)
you will get a compiler error, which tells you soon enough that something went wrong....
In DXL, 'true' and 'false' are just variables:
void printTrueFalse()
{ print "'true' = " true "\t'false' = " false "\n"
}
printTrueFalse()
true = false
printTrueFalse()
// reset the "true" value of variable "true"; since it is stored in top context
true = 1 == 1
printTrueFalse()
prints this:
'true' = true 'false' = false
'true' = false 'false' = false
'true' = true 'false' = false
-Louie
|
|
Re: User disabled property llandale - Wed Jun 20 14:39:21 EDT 2012 SystemAdmin - Wed Jun 20 05:51:23 EDT 2012
Even though you think the script works with using either "=" or "==", it's not.
Now others can possibly explain this better than I can but here goes.
The statement within parenthesis (bldis = true) is not actually performing a conditional test, it is actually forcing the boolean variable "bldis" to be equal to "true".
So the line "if (bldis = true)" becomes the same as writing "if (true)" so the conditional "if" statement is always resolving to be true and consequently you get a listing of every user.
I find that your script works fine if you use "==".
BTW - as a tip, if you use the code mark up tag above and below your code, it will look like the following - (all mark up tags are listed in the Plain Text Help box that appears next to the DW Forums editor.
I've added indentation and a few other pedant type adjustments
User usr
bool bldis = false
for usr in userList do {
bldis = usr.disabled
if (bldis == false){
string strEmail, strName
strEmail= usr.email
strName=usr.name
print strName "," strEmail "," bldis "\n"
}
}
Paul Miller
Melbourne, Australia
I usually just say:
-
if ( bldis)
-
if (!bldis)
-
if (not bldis) // defined my own function "not".
if ( A1 and A2) then..
elseif( A1 and !A2) then..
elseif(!A1 and A2) then..
elseif(!A1 and !A2) then..
else{} // all cases covered
As for your indentation; yes I never had "C", but it seems to me you should not do this:
for loop {
if (Question) {
whatever
}
}
but should put the closing brace at the same level as the original line
for loop {
if (Question) {
whatever
}
}
As you know I do this, since its far easier for me to see lined up braces:
for loop
{ if (Question)
{ whatever
}
}
-Louie
|
|
Re: User disabled property SystemAdmin - Wed Jun 20 15:15:25 EDT 2012 llandale - Wed Jun 20 14:30:44 EDT 2012
In DXL, 'true' and 'false' are just variables:
void printTrueFalse()
{ print "'true' = " true "\t'false' = " false "\n"
}
printTrueFalse()
true = false
printTrueFalse()
// reset the "true" value of variable "true"; since it is stored in top context
true = 1 == 1
printTrueFalse()
prints this:
'true' = true 'false' = false
'true' = false 'false' = false
'true' = true 'false' = false
-Louie
Hi Louis,
thanks for the info - why am I not surprised that something does not work in DXL as I expected it to do? :-)
Regards,
Mike
|
|
Re: User disabled property llandale - Thu Jun 21 11:48:39 EDT 2012 SystemAdmin - Wed Jun 20 15:15:25 EDT 2012
Hi Louis,
thanks for the info - why am I not surprised that something does not work in DXL as I expected it to do? :-)
Regards,
Mike
What is surprising, that is that I am continually "surprised".
You did use the correct words "as I expect". Many folks say "as is expected" suggesting that what they expect is "normal" or "natural" suggesting that other folk's expectations are "wrong". Those folks have a harder time adjusting to the actual reality since they believe are "right", but the "I" folks believe they are just "different".
-Louie
And yes, I do realize I'm "different" quite a bit!
|
|